<template>
  <!-- hidden PageHeaderWrapper title demo -->
  <page-header-wrapper :title="false">
    <a-card :body-style="{ padding: '24px 32px' }" :bordered="false">
      <a-form @submit="handleSubmit" :form="form">
        <a-form-item
          label="退库店面"
          :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
        >
          <a-select v-decorator="['storeId']" placeholder="请选择" >
            <a-select-option :value="i.id" v-for="i in storeoption" :key="i.id">{{ i.storeName }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="供应商"
          :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
        >
          <a-select v-decorator="['supplyId']" placeholder="请选择供应商" default-value="0">
            <a-select-option :value="i.id" v-for="i in supplyoption" :key="i.id">{{ i.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item :wrapperCol="{ span: 24 }" style="text-align: center">
          <a-button htmlType="submit" type="primary" icon="check">下一步</a-button>
          <!-- <a-button style="margin-left: 8px">{{ $t('form.basic-form.form.save') }}</a-button> -->
        </a-form-item>
      </a-form>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { getStoreListUsingPOST } from '@/api/api/mendianguanli.ts'
import { getSuppliesListUsingPOST } from '@/api/api/jingxiaoshangyunyingshangguanli.ts'
export default {
  name: 'BackstoreIndex',
  data() {
    return {
      form: this.$form.createForm(this),
      storeoption: [],
      supplyoption: [],
      optionParam: {
        pageNo: 1,
        pageSize: 999,
        queryCondition: '',
        status: '',
      },
    }
  },
  mounted() {
    this.getStoreOption()
    this.getSupOption()
  },
  methods: {
    getStoreOption() {
      getStoreListUsingPOST(this.optionParam)
        .then((res) => {
          this.storeoption = res.data.list
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    getSupOption() {
      getSuppliesListUsingPOST({...this.optionParam, types: 1})
        .then((res) => {
          this.supplyoption = res.data.list
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    // handler
    handleSubmit(e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          if(!values.storeId){
            this.$message.warn('请选择退库门店')
          }else if(!values.supplyId){
            this.$message.warn('请选择供应商')
          }else{
            this.$router.push({ path: `/purchasing/backstore/details`, query: { ...values } })
          }
        }
      })
    },
  },
}
</script>
